//
//  MaskView.m
//  AVFoundation
//
//  Created by shanlin on 2017/2/24.
//  Copyright © 2017年 shanlin. All rights reserved.
//

#import "MaskView.h"

@implementation MaskView

- (void)awakeFromNib  {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    [self setupUI];
}

// 搭建界面设置按钮
- (void)setupUI {
    for (int i = 0; i < 9; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"gesture_node_normal"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"gesture_node_selected"] forState:UIControlStateSelected];
        [self addSubview:btn];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat btnWH = 74;
    
    // 共有多少列
    int column = 3;
    CGFloat margin = (self.bounds.size.width - (btnWH * column)) / (column + 1);
    int curC = 0;
    int curR = 0;
    
    for (int i = 0; i < self.subviews.count; i++) {
        
        // 当前所在的列
        curC = i % column;
        // 当前所在的行
        curR = i / column;
        
        x = margin + (btnWH + margin) * curC;
        y = margin + (btnWH + margin) * curR;
        
        UIButton * btn = self.subviews[i];
        btn.frame = CGRectMake(x, y, btnWH, btnWH);
    }
}

@end
